//
//  main.m
//  OC_数字,字典复习
//
//  Created by dllo on 15/12/7.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Fraction.h"
#import "AddressBook.h"
#import "Contact.h"
#import "AddressBookV2.h"


int main(int argc, const char * argv[]) {
    @autoreleasepool {
  
#pragma mark - 复习1: 分数
#if 0
        {
            /** 创建对象 */
            Fraction *fra1 = [[Fraction alloc] initWithNum:1 deno:3];
            Fraction *fra2 = [[Fraction alloc] initWithNum:2 deno:5];
            
            /** 使用对象 */
            [fra2 addFraction:fra1];
            
            Fraction *addFra = [fra2 addFraction:fra1];
            NSLog(@"%ld/%ld", addFra.num, addFra.deno);
        }
#endif
        
#pragma mark - 复习: 通讯录
#if 1
        {
            /** 涉及到两个类: AddressBook(通讯录类) 和 Contact(联系人类) */
            
            /** 创建一个通讯录对象 */
            AddressBook *ab = [[AddressBook alloc] init];
            
            /** 创建两个联系人对象 */
            Contact *con1 = [[Contact alloc] initWithName:@"zhangsan" phoneNumber:@"13888888888"];
            Contact *con2 = [[Contact alloc] initWithName:@"lisi" phoneNumber:@"13955555555"];
            
            
            /** 使用通讯录对象方法 */
            [ab addContact:con1];
            [ab addContact:con2];
            

            /** 删除指定联系人 */
            [ab deleteContact:con2];
            
            /** 显示所有联系人 */
            [ab listAllContacts];
            
        }
#endif
        
#pragma maek - 复习: 通讯录(中等难度)
#if 0
        {
            Contact *con1 = [[Contact alloc] initWithName:@"zhangsan" phoneNumber:@"13888888888"];
            Contact *con2 = [[Contact alloc] initWithName:@"alisi" phoneNumber:@"13955555555"];
            Contact *con3 = [[Contact alloc] initWithName:@"lisisi" phoneNumber:@"139555555555"];
            Contact *con4 = [[Contact alloc] initWithName:@"zhangba" phoneNumber:@"13888882558888"];
            
            /** 创建通讯录对象 */
            AddressBookV2 *abV2 = [[AddressBookV2 alloc] init];
            
            /** 对象方法 */
            [abV2 addContact:con1];
            [abV2 addContact:con2];
            [abV2 addContact:con3];
            [abV2 addContact:con4];
            
            /** 显示所有联系人 */
            [abV2 listAllContact];
            NSLog(@"----------------------------------------------------------------------------");
            /** 显示某个分组下的所有联系人 */
            [abV2 listForGroup:@"l"];
   
        }
#endif
        
#pragma mark - 练习: 省市区
#if 0
        {
            NSString *file = [NSString stringWithContentsOfFile:@"/Users/dllo/Desktop/OC/OC_数字,字典复习/OC_数字,字典复习/area.txt" encoding:NSUTF8StringEncoding error:nil];
            NSLog(@"%@", file);
            
            /** 将字符串进行截取, 按照\n */
            NSArray *arr = [file componentsSeparatedByString:@"\n"];
            
            NSString *provinceName = nil;
            NSString *cityName = nil;
            NSString *areaName = nil;
            
            /** 创建中国数组 */
            NSMutableArray *chinaArr = [NSMutableArray array];
            
            /** 遍历数组 */
            for (NSString *line in arr) {
                
                if (![line hasPrefix:@" "]) {        /** 字符串不是以空格开头, 说明是省名 */
                    
                    provinceName = line;  /** 记录省名 */
                    
                    /** 创建省字典加入到中国数组中 */
                    NSMutableArray *cityArr = [NSMutableArray array];
                    NSMutableDictionary *proDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:provinceName, @"省名", cityArr, @"市", nil];
                    
                    [chinaArr addObject:proDic];
  
                } else if (![line hasPrefix:@"    "]){
                    
                    /** 说明是市名 */
                    
                    cityName = line;  /**< 记录市名 */
                    /** 创建市字典, 添加在对应省的市数组中 */
                    NSMutableArray *areaArr = [NSMutableArray array];
                    NSMutableDictionary *cityDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:cityName, @"市名", areaArr, @"区", nil];
                    
                    /** 从中国数组里面找出对应省的市数组 */
                    NSMutableArray *tempArr = [[chinaArr lastObject] objectForKey:@"市"];
                    [tempArr addObject:cityDic];
                } else {
                    
                    areaName = line;  /** 记录下区名 */
                    
                    /** 找出区所在省的市数组的相应市的区数组 */
                    NSMutableArray *tempArr = [[chinaArr lastObject] objectForKey:@"市"];
                    NSMutableArray * tempAreas = [[tempArr lastObject] objectForKey:@"区"];
                    [tempAreas addObject:areaName];
                }
 
            }
     
        }
#endif
        
        
    }
    return 0;
}
